<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>backbone示例</title>
		<script src="js/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="//cdn.bootcss.com/underscore.js/1.8.3/underscore-min.js"></script>
		<script src="//cdn.bootcss.com/backbone.js/1.2.3/backbone-min.js"></script>
	</head>
	<script type="text/javascript">
		(function() {
			var animal = Backbone.Model.extend({
				initialize: function() {
					console.log('init way')
				},
				defaults: {
					name: 'dog',
					age: 3,
					weight: '25kg',
					master: 'weichao'
				}
			});
			var animals = Backbone.Collection.extend({
				model: animal
			});
			var cat = new animal({
				name: "cat"
			});
			var pig = new animal({
				name: "pig"
			});
			var duck = new animal({
				name: "duck"
			});
			var chick = new animal({
				name: "chick"
			});
			var animalList = new animals;
			animalList.add(cat);
			animalList.add(pig);
			animalList.add(duck);
			animalList.add(chick);
			animalList.remove(chick);
			
			animalList.each(function(m) {
				console.log(m.get('name'));
			})
/*			
 *            animalList.bind('reset',function(){animalList.each(function(animal){})}) 
 * 2、使用 fetch 从服务器端获取数据 
				url: ".../",
				seuccess: function(_list, respones) {
					_list.each(function(animal){
						alert(animal.get('name'));
					})
				},
				error: function() {alert('error');}
			});*/  
		})(jQuery)
	</script>

	<body>
	</body>

</html>